# 导入必要的包
import requests
from config import *


def login(username, pwd, code, msg):
    response = requests.get(f"{BASE_URL}/api/captchaImage")
    uuid = response.json()["uuid"]

    # 准备登录数据
    login_data = {
        "username": username,
        "password": pwd,
        "code": "2",
        "uuid": uuid
    }
    # 发送登录请求
    response = requests.post(url=f"{BASE_URL}/api/login", json=login_data)
    # 打印响应结果
    print(response.json())
    # 断言响应状态码和内容
    assert response.status_code == 200
    assert response.json().get("code") == code
    assert msg in response.text


if __name__ == '__main__':
    test_data = [
        ("admin", "HM_2023_test", 200, "成功"),
        ("", "HM_2023_test", 500, "错误"),
        ("admin", "", 500, "错误"),
    ]
    for i in test_data:
        login(*i)
        # login(i[0], i[1], i[2], i[3])

